<%@ page language="java" contentType="text/html"  pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="lc" uri="/WEB-INF/tld/lcfms.tld" %>																			
<!DOCTYPE html>	
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link rel="stylesheet" href="${CSS}bootstrap.min.css">
		<link rel="stylesheet" href="${CSS}iconfont.css"/>	
		<link rel="stylesheet" href="${APP}statics/jstree/jstree.min.css">
		<link rel="stylesheet" href="${CSS}form.css">		
		<script src="${JS}jquery-3.2.1.min.js"></script>
		<script src="${JS}bootstrap.min.js"></script>
		<script src="${APP}statics/jstree/jstree.min.js"></script>
		<script src="${JS}form.js"></script>		
		<script src="${JS}../../layer/layer.js"></script>
	</head>
	<body>
		<div class="container-fluid">
			<div class="row">
				<div class="form-box form-color-grey">
					<div class="form-header">
						<h6 class="form-title">
							<i class="iconfont icon-edit size-16">
							</i>
							<lc:if test="${group.rid ne null && group.rid ne 0}">修改角色</lc:if><lc:else>添加角色</lc:else>
						</h6>
					</div>
					<c:set var="method" value="ajax"/>
					<form class="form-horizontal" method="${method}" action="add_group" name="myform">
			    		<lc:if test="${group.rid ne null && group.rid ne 0}">
			    			<input type="hidden" name="rid" value="${group.rid}"/>
			    		</lc:if>
						<div class="form-body">
							<div class="form-group">
								<label class="col-sm-2 control-label">
									角色名称：
								</label>
								<div class="col-sm-10">
									<input class="form-control" value="${group.rname}" name="rname" type="text" attribute="unempty unNum"
									placeholder="请输入用户组名称" error="输入有误" success="输入正确">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">
									角色描述：
								</label>
								<div class="col-sm-10">
									<textarea class="form-control" name="rdesc" rows="5" cols="50" maxnum="50">${group.rdesc}</textarea>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">
									控制器权限：
								</label>
								<div class="col-sm-10">
									<div class="checkbox">
									    <c:forEach var="tle" varStatus="key" items="${paset}">
									    <label class="checkbox-inline" style="position:relative;left:-20px;top:5px;">${key.count}、${tle}</label>
										<div class="checkbox">
										<c:forEach var="aal" items="${permit}">
										<c:if test="${aal[1] eq tle}">
										<label>
										    <c:set var="cls" value="${aal[0]}"/>
											<input name="permit" type="checkbox" value="${aal[0]}" <c:if test="${groupPermit.contains(cls)}">checked</c:if>/>
											<span class="lbl"> ${aal[2]}</span>&nbsp;&nbsp;
										</label>
										</c:if>							
										</c:forEach>																							
										</div>	
										</c:forEach>				
									</div>									
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">
									菜单权限：
								</label>
								<div class="col-sm-10">
								<div id="jstree" class="demo" style="margin-top:1em;"></div>
									<script>
									$('#jstree').jstree({
										'plugins':["wholerow","checkbox"],
										'core' : {'data' : ${item}},
										'checkbox': {
						                    "three_state": false
						                }
									});
									</script>									
								</div>
							</div>
						</div>
						<div class="form-footer">
							<div class="form-group">
								<label class="col-sm-2">
								</label>
								<div class="col-sm-10">
									<button type="button" id="save" class="btn btn-sm btn-grey">
										<i class="fa fa-check">
										</i>
										提交
									</button>
									<button type="reset" id="reset" class="btn btn-sm btn-grey">
										<i class="fa fa-undo">
										</i>
										重置
									</button>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<script>			
		var myform=form.init("myform");	
		$("#save").click(function(){
			var array=$('#jstree').jstree(true).get_selected(true);
			var r=[];
			for(var i=0;i<array.length;i++){
				r.push(array[i].id);
			}
			myform.put("gitem",r.join(","));
			myform.submit(function(res){
				layer.msg(res.msg);
				setTimeout(function(){
	        		location.href=res.url;
        		},1000);
			});
		});
		$("#reset").click(function(){
			myform.reset();
		});
		</script>
	</body>
</html>
				